package com.youchuang.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

import com.youchuang.bean.Manager;
import com.youchuang.common.HibernateConnection;
import com.youchuang.dao.ManagerDAO;

@Repository("managerDAO")
public class ManagerDAOImpl implements ManagerDAO {

	private static final String HQL_FIND_ALL = "from Manager";
	private static final String HQL_FIND_BY_ACCOUNT = "from Manager where account= :account";

	@Resource
	private HibernateConnection<Manager> hibernateConnection;

	public void save(Manager object) {
		//Do nothing because of it unusual
	}

	public void delete(Manager object) {
		//Do nothing because of it unusual
	}

	public int update(Manager object) {
		hibernateConnection.update(object);
		return 1;
	}

	public Manager queryByAccount(String account) {
		Map<String, Object> params = new HashMap<>();
		params.put("account", account);
		List<Manager> list = hibernateConnection.find(HQL_FIND_BY_ACCOUNT, params);
		if (CollectionUtils.isEmpty(list)) {
			return null;
		}
		return list.get(0);
	}

	public List<Manager> queryAll() {
		return hibernateConnection.find(HQL_FIND_ALL);
	}

}
